package com.leetcode.partition6;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author `RKC`
 * @date 2022/1/18 17:45
 */
public class LC539最小时间差 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        List<String> timePoints = new ArrayList<>();
        Collections.addAll(timePoints, s);
        writer.write(findMinDifference(timePoints) + "\n");
        writer.flush();
    }

    public static int findMinDifference(List<String> timePoints) {
        List<Integer> minutes = new ArrayList<>(timePoints.size());
        for (String timePoint : timePoints) {
            String[] s = timePoint.split(":");
            int h = Integer.parseInt(s[0]), m = Integer.parseInt(s[1]);
            minutes.add(h * 60 + m);
            //多加一个周期，便于直接判断最小时间差
            minutes.add(h * 60 + m + 1440);
        }
        Collections.sort(minutes);
        int answer = 0x3f3f3f3f;
        for (int i = 0; i < minutes.size() - 1; i++) {
            answer = Math.min(answer, minutes.get(i + 1) - minutes.get(i));
        }
        return answer;
    }
}
